package com.example.travelplan.app;

import android.app.ActivityGroup;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.ImageButton;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.io.InputStream;
import android.graphics.drawable.Drawable;
import java.io.File;
import 	java.io.BufferedInputStream;
import java.io.BufferedReader;

import com.example.travelplan.app.dominio.*;
import 	android.content.Context;
import 	android.util.Log;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import 	android.os.Environment;
import android.graphics.BitmapFactory;

public class FullscreenActivity extends ActivityGroup {
    public final static String APP_PATH_SD_CARD = "/DesiredSubfolderName/";
    public final static String APP_THUMBNAIL_PATH_SD_CARD = "thumbnails";

    /**
     * Called when the activity is first created.
     */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);

        getActionBar().hide();

        List<Cidade> listaCidade = new ArrayList<Cidade>();
        listaCidade = Controller.getInstance().obterListaCidade();
        List<Roteiro> listaRoteiro = Controller.getInstance().obterListaRoteiro();

        Roteiro roteiro = new Roteiro(listaCidade.get(0));

        roteiro.setM_dataIda(getDataDia("25/06/2014"));
        roteiro.setM_datavolta(getDataDia("25/07/2014"));
        String[] listStringAtividades = new String[1];
        //Controller.getInstance().criarRoteiro(roteiro,listStringAtividades);

        // create the TabHost that will contain the Tabs
        TabHost tabHost = (TabHost) findViewById(R.id.tabhost);

        tabHost.setup(getLocalActivityManager());

        TabHost.TabSpec tab1;
        TabHost.TabSpec tab2;
        TabHost.TabSpec tab3;
        TabHost.TabSpec tab4;
        TabHost.TabSpec tab5;

        // Set the Tab name and Activity
        // that will be opened when particular Tab will be selected

        Intent intent;

        intent = new Intent().setClass(this, tabprincipalActivity.class);
        tab1 = tabHost.newTabSpec("1").setIndicator("")
                .setContent(intent);
        tab1.setIndicator("", getResources().getDrawable(R.drawable.ic_home));

        intent = new Intent().setClass(this, tabpesquisarActivity.class);
        tab2 = tabHost.newTabSpec("2").setIndicator("")
                .setContent(intent);
        tab2.setIndicator("", getResources().getDrawable(R.drawable.ic_queue_add));

        intent = new Intent().setClass(this, tabvisualizarActivity.class);
        tab3 = tabHost.newTabSpec("3").setIndicator("")
                .setContent(intent);
        tab3.setIndicator("", getResources().getDrawable(R.drawable.ic_airplane_mode_off));

        intent = new Intent().setClass(this, tabcalendarioActivity.class);
        tab4 = tabHost.newTabSpec("4").setIndicator("")
                .setContent(intent);
        tab4.setIndicator("", getResources().getDrawable(R.drawable.ic_date));

        intent = new Intent().setClass(this, tabconfiguracaoActivity.class);
        tab5 = tabHost.newTabSpec("5").setIndicator("")
                .setContent(intent);
        tab5.setIndicator("", getResources().getDrawable(R.drawable.ic_cog));


        /** Add the tabs  to the TabHost to display. */
        tabHost.addTab(tab1);
        tabHost.addTab(tab2);
        tabHost.addTab(tab3);
        tabHost.addTab(tab4);
        tabHost.addTab(tab5);

        Bundle b = getIntent().getExtras();
        if(b != null) {
            int tabCorrente = b.getInt("idTab");
            tabHost.setCurrentTab(tabCorrente);
        }

    }


    private Date getDataDia(String _data){
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

        Date data = null;
        try {
            data = sdf.parse(_data);
        }

        catch (Exception e) {
            data = new Date();
        }

        return data;
    }

}
